<template>
    <div>
        <van-cell-group>
            <van-field v-model="value" placeholder="请输入商品名称" />
        </van-cell-group>
        <van-button type="info" size="large" @click="addgoods">添加商品</van-button>
    </div>
</template>
<script>
export default {
  data () {
    return {
      value: ''
    }
  },
  methods: {
    // 点击添加商品时触发
    async addgoods () {
    // 判断输入框的值是否为空
      if (this.value.trim().length === 0) return this.$notify('商品名称不能为空')
      const { data: res } = await this.$http.post('/api/addproduct', {
        name: this.value
      })
      this.$router.push('/search')
      if (res.status === 0) {
        this.$notify({ type: 'success', message: res.message })
        this.value = ''
      }
    }
  }
}
</script>
<style scoped lang="less">
.van-button {
    width: 90%;
    margin-left: 5%;
    margin-top: 40px;
}

</style>
